package com.joyxy.spider.mapscript.operation;

/**
 * 吹怪操作
 * 操作数: 5
 * 参数: StarX/EndX/YTime/X/Face/XTime/Sit
 */
public class LureMonsterOperation extends BaseOperation {
    /** 起点横坐标 */
    private int startX;
    /** 终点横坐标 */
    private int endX;
    /** 引怪时间（秒） */
    private int lureTime;
    /** 吹怪点横坐标 */
    private int blowX;
    /** 吹怪方向: 0-向左, 1-向右 */
    private int direction;
    /** 吹怪后几秒开始休息 */
    private int restTime;
    /** 是否坐下: 0-否, 1-是 */
    private int sitDown;
    
    public LureMonsterOperation(int startX, int endX, int lureTime, int blowX, int direction, int restTime, int sitDown) {
        super(5, "吹怪");
        this.startX = startX;
        this.endX = endX;
        this.lureTime = lureTime;
        this.blowX = blowX;
        this.direction = direction;
        this.restTime = restTime;
        this.sitDown = sitDown;
    }
    
    /**
     * 从参数数组创建吹怪操作
     */
    public static LureMonsterOperation fromParameters(int[] parameters) {
        if (parameters == null || parameters.length < 7) {
            throw new IllegalArgumentException("吹怪操作需要7个参数: StarX/EndX/YTime/X/Face/XTime/Sit");
        }
        return new LureMonsterOperation(parameters[0], parameters[1], parameters[2], parameters[3], 
                                       parameters[4], parameters[5], parameters[6]);
    }
    
    @Override
    public void execute() {
        String dirDesc = getDirectionDescription();
        String sitDesc = sitDown == 1 ? "坐下" : "不坐下";
        System.out.println("执行吹怪: 从" + startX + "到" + endX + " 引怪" + lureTime + "秒, " +
                         "在" + blowX + "处" + dirDesc + "吹怪, " + restTime + "秒后休息, " + sitDesc);
        // 这里应该调用实际的吹怪逻辑
    }
    
    @Override
    public boolean isValid() {
        return startX >= 0 && endX >= 0 && lureTime > 0 && blowX >= 0 && 
               (direction == 0 || direction == 1) && restTime >= 0 && 
               (sitDown == 0 || sitDown == 1);
    }
    
    @Override
    public String getDetailInfo() {
        return String.format("吹怪: 路径%d→%d, 引怪%d秒, 吹怪点%d(%s), 休息%d秒, %s", 
                startX, endX, lureTime, blowX, getDirectionDescription(), restTime, 
                sitDown == 1 ? "坐下" : "不坐下");
    }
    
    /**
     * 获取吹怪方向描述
     */
    public String getDirectionDescription() {
        return direction == 0 ? "向左" : "向右";
    }
    
    /**
     * 获取移动距离
     */
    public int getMoveDistance() {
        return Math.abs(endX - startX);
    }
    
    /**
     * 检查是否为长距离引怪
     */
    public boolean isLongDistanceLure() {
        return getMoveDistance() > 50; // 超过50像素认为是长距离
    }
    
    /**
     * 检查是否为长时间引怪
     */
    public boolean isLongTimeLure() {
        return lureTime >= 30; // 超过30秒认为是长时间
    }
    
    // Getter methods
    public int getStartX() { return startX; }
    public int getEndX() { return endX; }
    public int getLureTime() { return lureTime; }
    public int getBlowX() { return blowX; }
    public int getDirection() { return direction; }
    public int getRestTime() { return restTime; }
    public int getSitDown() { return sitDown; }
    public boolean shouldSitDown() { return sitDown == 1; }
    
    @Override
    public String toString() {
        return String.format("LureMonster{path=%d→%d, lureTime=%ds, blow=(%d,%s), rest=%ds, sit=%s}", 
                startX, endX, lureTime, blowX, getDirectionDescription(), restTime, shouldSitDown());
    }
} 